const express = require("express");
const authMiddleware = require("../middlewares/server.authorization.middle.js");
const api = require("../modules/api.js");
const router = express.Router();

/*---------用户管理页面-->首页----------*/
router.get("/", authMiddleware.login_required, (req, res, next)=>{
    res.render("admin/index.html", {req});
});

/*---------用户管理页面-->加工管理--------*/
router.get("/process", authMiddleware.login_required, (req, res, next)=>{
    res.render("admin/process.html", {req});
});

/*---------用户管理页面-->订单管理-----------*/
router.get("/order", authMiddleware.login_required, (req,res, next)=>{
	Promise.all([
			api.order_list.bind(req)({pageNo: 1, pageSize: 10})
	])
	.then(data=>{
		let list = data[0].result.list || [];
		let page = data[0].result.page;
        let base_url = req.path;
        let pageNo = 1;
		res.render("admin/order.html", {req, list, page, base_url, pageNo});
	});
});


router.get("/order/:id", authMiddleware.login_required, (req, res, next)=>{
	res.render("admin/order_detail.html");
});


module.exports = router;